﻿using KalevaAalto.DataPart.Excel.Base;
using KalevaAalto.DataPart.Models;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.Excel.Epplus
{
    internal class EpplusRows : BaseRows
    {
        private int _startRow;
        private int _endRow;
        private ExcelWorksheet _worksheet;
        private ExcelRangeRow _rows => _worksheet.Rows[(int)_startRow, (int)_endRow];
        public EpplusRows(BaseWorksheet worksheet, ExcelRangeRow rows) : base(worksheet)
        {
            _startRow = rows.StartRow;
            _endRow = rows.EndRow;
            _worksheet = rows.Range.Worksheet;
        }

        public override IStyle Sytle =>new EpplusStyle(_rows.Style);

        public override BaseRows this[int index] => new EpplusRows(Worksheet, _worksheet.Rows[_startRow + index - 1]);
        public override int Count => _endRow - _startRow + 1;
        public override double Height { set => _rows.Height = value; get => _rows.Height; }

        public override IEnumerator<BaseRows> GetEnumerator()=> _rows.Select(it => new EpplusRows(Worksheet, it)).GetEnumerator();
    }
}
